<include file="public@header"/>
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
    .cars{
        display: block;
        width: 30%;
        height: 34px;
        padding: 6px 12px;
        font-size: 14px;
        line-height: 1.42857143;
        color: #2C3E50;
        background-color: #fff;
        background-image: none;
        border: 1px solid #dce4ec;
        border-radius: 0;
        -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
        box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
        -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
        -o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
        transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;}
        .cars option{ width: 30px; }
</style>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
        <input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
               style="width: 200px;" title="图片名称">
        <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
             onclick="imagePreviewDialog(this.src);">
        <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
    </li>
</script>
<script type="text/html" id="files-item-tpl">
    <li id="saved-file{id}">
        <input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
        <input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
               style="width: 200px;" title="文件名称">
        <a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
        <a href="javascript:uploadOne('文件上传','#file-{id}','file');">替换</a>
        <a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
    </li>
</script>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('Ad/index')}">广告位置</a></li>
        <li class="active"><a href="{:url('Adlist/add')}">添加分类</a></li>
    </ul>
    <form action="{:url('Adlist/edit')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
        <div class="row">
            <div class="col-md-8">
                <table class="table table-bordered col-md-4">
                
             <!--         <tr>
                        <th width="100">分类<span class="form-required">*</span></th>
                        <td>
                            <select class="cars" name="post[id]"> 
                            </select>
                        </td>
                    </tr> -->
                    <tr>
                        <th style="width: 80px">标题<span class="form-required">*</span></th>
                        <td>
                            <input style="width: 70%" class="form-control col-md-6" type="text" name="post[ad_name]"
                                   id="title" required value="{$post.ad_name}" placeholder="请输入标题"/>
                        </td>
                    </tr>
                    <tr>
                        <th style="width: 80px"><b>广告图集<span class="form-required">*</span></b></th>
                        <td>
                            <div class="images_upload">
                                <div>
                                    <ul id="photos" class="pic-list list-unstyled form-inline">
                                        <notempty name="photos">
                                            <foreach name="photos" item="vo">
                                                <php>$img_url=cmf_get_image_preview_url($vo);</php>
                                                <li id="saved-image{$key}">
                                                    <input id="photo-{$key}" type="hidden" name="photo_urls[]"
                                                           value="{$vo}">
                                                    <img id="photo-{$key}-preview"
                                                         src="{:cmf_get_image_preview_url($vo)}"
                                                         style="height:36px;width: 36px;"
                                                         onclick="parent.imagePreviewDialog(this.src);">
                                                    <a href="javascript:uploadOneImage('图片上传','#photo-{$key}');">替换</a>
                                                    <a href="javascript:(function(){$('#saved-image{$key}').remove();})();">移除</a>
                                                </li>
                                            </foreach>
                                        </notempty>
                                    </ul>
                                    <a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');"
                                       class="btn btn-sm btn-default">选择图片</a>
                                </div>
                            </div>
                        </td>
                    </tr>
              <!--        <tr>
                        <th width="90"><b>广告图</b></th>
                        
                    </tr> -->
                    <style type="text/css">
                        textarea{width: 100%;height: 80px}
                        #photos{display: inline-block;width: 100%;}
                        .pic-list li{float: left;margin-right: 10px}
                    </style>
                    <tr>
                        <th style="width: 60px"><b>备注信息</b></th>
                        <td>
                            <textarea name="post[content]" style="width: 70%">{$post.content|default=''}</textarea>
                        </td>
                    </tr>
                    <input style="display:none" class="form-control js-bootstrap-datetime" type="text" name="post[ad_id]"
                                   value="{$ad_id}">
                </table>
            <div>
                <div class="form-group">
                    <div class="col-sm-10">
                        <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
                        <!-- <a class="btn btn-default" href="javascript:;">新增广告</a> -->
                    </div>
                </div>
            </div>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
  $('document').ready(function () {
    var id = {$ad_id};
      $.ajax({
            url:"{:url('Adlist/adajax')}",
            type:"post",
            dataType:"json",
            data:{id:id},
            success:function(data){
                for (var i = 0; i  < data.length; i++) {
                    if (data[i].id == id) {
                        var option = "<option selected='selected' value='"+data[i].id+"'>"+data[i].name+"</option>";
                    }else{
                        var option = "<option value='"+data[i].id+"'>"+data[i].name+"</option>";
                    }
                    $('.cars').append(option);
                };
            },
            error:function(e){
                alert("错误！！");
                window.clearInterval(timer);
            }
        });
  })
</script>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript">
   $('#title').blur(function () {
       var key = $('#title').val();
       $('#keywords').val(key);
   })
   $('#edui1_iframeholder #ueditor_0 html body p').hover(function () {
       alert(1111);
       var key = $('#edui1_iframeholder #ueditor_0 html body').html();
       // $('#keywords').val(key);
   })
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
    $(function () {

        editorcontent = new baidu.editor.ui.Editor();
        editorcontent.render('content');
        try {
            editorcontent.sync();
        } catch (err) {
        }

        $('.btn-cancel-thumbnail').click(function () {
            $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
            $('#thumbnail').val('');
        });

    });
    $('#thumbnail').change(function () {
        alert(111);
         var img = $(this).val();
         $('#thumbnail-preview1').attr('src',img);
    })

    function doSelectCategory() {
        var selectedCategoriesId = $('#js-categories-id-input').val();
        openIframeLayer("{:url('AdminCategory/select')}?ids=" + selectedCategoriesId, '请选择分类', {
            area: ['700px', '400px'],
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //do something

                var iframeWin          = window[layero.find('iframe')[0]['name']];
                var selectedCategories = iframeWin.confirm();
                if (selectedCategories.selectedCategoriesId.length == 0) {
                    layer.msg('请选择分类');
                    return;
                }
                $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
                $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
                //console.log(layer.getFrameIndex(index));
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }
</script>
</body>
</html>
